package com.ssy.lingxi.product.utils;

import java.io.File;

/**
 * @author jw.chen
 * @version 2.0.0
 * @description 文件操作工具类
 * @date 2021/12/1
 */
public class FileUtil {

    /**
     * 删除目录下所有文件
     * @param dir       目录
     * @return  是否删除成功
     */
    public static boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            String[] children = dir.list();
            if(children != null && children.length > 0){
                for (String s : children) {
                    boolean success = deleteDir(new File(dir, s));
                    if (!success) {
                        return false;
                    }
                }
            }
        }
        return dir.delete();
    }
}
